home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / orca / rolenames.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  15.3 KB  |  331 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Provides methods that convert the role name of an Accessible
  5. object into localized strings for speech and braille.'''
  6. __id__ = '$Id: rolenames.py 4484 2009-01-31 15:40:03Z wwalker $'
  7. __version__ = '$Revision: 4484 $'
  8. __date__ = '$Date: 2009-01-31 10:40:03 -0500 (Sat, 31 Jan 2009) $'
  9. __copyright__ = 'Copyright (c) 2004-2008 Sun Microsystems Inc.'
  10. __license__ = 'LGPL'
  11. import debug
  12. import settings
  13. import pyatspi
  14. from orca_i18n import _
  15. from orca_i18n import C_
  16. ROLE_INVALID = 'invalid'
  17. ROLE_ACCEL_LABEL = 'accelerator label'
  18. ROLE_ALERT = 'alert'
  19. ROLE_ANIMATION = 'animation'
  20. ROLE_ARROW = 'arrow'
  21. ROLE_CALENDAR = 'calendar'
  22. ROLE_CAPTION = 'caption'
  23. ROLE_CANVAS = 'canvas'
  24. ROLE_CHECK_BOX = 'check box'
  25. ROLE_CHECK_MENU_ITEM = 'check menu item'
  26. ROLE_COLOR_CHOOSER = 'color chooser'
  27. ROLE_COLUMN_HEADER = 'column header'
  28. ROLE_COMBO_BOX = 'combo box'
  29. ROLE_DATE_EDITOR = 'dateeditor'
  30. ROLE_DESKTOP_ICON = 'desktop icon'
  31. ROLE_DESKTOP_FRAME = 'desktop frame'
  32. ROLE_DIAL = 'dial'
  33. ROLE_DIALOG = 'dialog'
  34. ROLE_DIRECTORY_PANE = 'directory pane'
  35. ROLE_DOCUMENT_FRAME = 'document frame'
  36. ROLE_DRAWING_AREA = 'drawing area'
  37. ROLE_ENTRY = 'entry'
  38. ROLE_FILE_CHOOSER = 'file chooser'
  39. ROLE_FILLER = 'filler'
  40. ROLE_FONT_CHOOSER = 'fontchooser'
  41. ROLE_FORM = 'form'
  42. ROLE_FRAME = 'frame'
  43. ROLE_GLASS_PANE = 'glass pane'
  44. ROLE_HEADING = 'heading'
  45. ROLE_HTML_CONTAINER = 'html container'
  46. ROLE_ICON = 'icon'
  47. ROLE_IMAGE = 'image'
  48. ROLE_INTERNAL_FRAME = 'internal frame'
  49. ROLE_INPUT_METHOD_WINDOW = 'input method window'
  50. ROLE_LABEL = 'label'
  51. ROLE_LAYERED_PANE = 'layered pane'
  52. ROLE_LINK = 'link'
  53. ROLE_LIST = 'list'
  54. ROLE_LIST_ITEM = 'list item'
  55. ROLE_MENU = 'menu'
  56. ROLE_MENU_BAR = 'menu bar'
  57. ROLE_MENU_ITEM = 'menu item'
  58. ROLE_OPTION_PANE = 'option pane'
  59. ROLE_PAGE_TAB = 'page tab'
  60. ROLE_PAGE_TAB_LIST = 'page tab list'
  61. ROLE_PANEL = 'panel'
  62. ROLE_PASSWORD_TEXT = 'password text'
  63. ROLE_POPUP_MENU = 'popup menu'
  64. ROLE_PROGRESS_BAR = 'progress bar'
  65. ROLE_PUSH_BUTTON = 'push button'
  66. ROLE_RADIO_BUTTON = 'radio button'
  67. ROLE_RADIO_MENU_ITEM = 'radio menu item'
  68. ROLE_ROOT_PANE = 'root pane'
  69. ROLE_ROW_HEADER = 'row header'
  70. ROLE_SCROLL_BAR = 'scroll bar'
  71. ROLE_SCROLL_PANE = 'scroll pane'
  72. ROLE_SECTION = 'section'
  73. ROLE_SEPARATOR = 'separator'
  74. ROLE_SLIDER = 'slider'
  75. ROLE_SPLIT_PANE = 'split pane'
  76. ROLE_SPIN_BOX = 'spinbox'
  77. ROLE_SPIN_BUTTON = 'spin button'
  78. ROLE_STATUSBAR = 'statusbar'
  79. ROLE_TABLE = 'table'
  80. ROLE_TABLE_CELL = 'table cell'
  81. ROLE_TABLE_COLUMN_HEADER = 'table column header'
  82. ROLE_TABLE_ROW_HEADER = 'table row header'
  83. ROLE_TEAR_OFF_MENU_ITEM = 'tear off menu item'
  84. ROLE_TERMINAL = 'terminal'
  85. ROLE_TEXT = 'text'
  86. ROLE_TOGGLE_BUTTON = 'toggle button'
  87. ROLE_TOOL_BAR = 'tool bar'
  88. ROLE_TOOL_TIP = 'tool tip'
  89. ROLE_TREE = 'tree'
  90. ROLE_TREE_TABLE = 'tree table'
  91. ROLE_UNKNOWN = 'unknown'
  92. ROLE_VIEWPORT = 'viewport'
  93. ROLE_WINDOW = 'window'
  94. ROLE_HEADER = 'header'
  95. ROLE_FOOTER = 'footer'
  96. ROLE_PARAGRAPH = 'paragraph'
  97. ROLE_APPLICATION = 'application'
  98. ROLE_AUTOCOMPLETE = 'autocomplete'
  99. ROLE_EDITBAR = 'edit bar'
  100. ROLE_EMBEDDED = 'embedded component'
  101.  
  102. class Rolename:
  103.     '''Provides localized forms of rolenames for speech and Braille.
  104.     '''
  105.     
  106.     def __init__(self, rolename, brailleShort, brailleLong, speech):
  107.         '''Created a new rolename with the given parameters.
  108.  
  109.         Arguments:
  110.         - rolename:     the internationalized (e.g., machine) name for the role
  111.         - brailleShort: the localized short string for Braille display
  112.         - brailleLong:  the localized long string for Braille display
  113.         - speech:       the localized string to speak for speech
  114.         '''
  115.         self.rolename = rolename
  116.         self.brailleShort = brailleShort
  117.         self.brailleLong = brailleLong
  118.         self.speech = speech
  119.  
  120.  
  121. rolenames = { }
  122. rolenames[ROLE_INVALID] = Rolename(ROLE_INVALID, _('???'), _('Invalid'), _('invalid'))
  123. rolenames[ROLE_ACCEL_LABEL] = Rolename(ROLE_ACCEL_LABEL, _('acc'), _('Accelerator'), _('accelerator'))
  124. rolenames[ROLE_ALERT] = Rolename(ROLE_ALERT, _('alrt'), _('Alert'), _('alert'))
  125. rolenames[ROLE_ANIMATION] = Rolename(ROLE_ANIMATION, _('anim'), _('Animation'), _('animation'))
  126. rolenames[ROLE_ARROW] = Rolename(ROLE_ARROW, _('arw'), _('Arrow'), _('arrow'))
  127. rolenames[ROLE_CALENDAR] = Rolename(ROLE_CALENDAR, _('cal'), _('Calendar'), _('calendar'))
  128. rolenames[ROLE_CANVAS] = Rolename(ROLE_CANVAS, _('cnv'), _('Canvas'), _('canvas'))
  129. rolenames[ROLE_CAPTION] = Rolename(ROLE_CAPTION, _('cptn'), _('Caption'), _('caption'))
  130. rolenames[ROLE_CHECK_BOX] = Rolename(ROLE_CHECK_BOX, _('chk'), _('CheckBox'), _('check box'))
  131. rolenames[ROLE_CHECK_MENU_ITEM] = Rolename(ROLE_CHECK_MENU_ITEM, _('chk'), _('CheckItem'), _('check item'))
  132. rolenames[ROLE_COLOR_CHOOSER] = Rolename(ROLE_COLOR_CHOOSER, _('clrchsr'), _('ColorChooser'), _('color chooser'))
  133. rolenames[ROLE_COLUMN_HEADER] = Rolename(ROLE_COLUMN_HEADER, _('colhdr'), _('ColumnHeader'), _('column header'))
  134. rolenames[ROLE_COMBO_BOX] = Rolename(ROLE_COMBO_BOX, _('cbo'), _('Combo'), _('combo box'))
  135. rolenames[ROLE_DATE_EDITOR] = Rolename(ROLE_DATE_EDITOR, _('dat'), _('DateEditor'), _('date editor'))
  136. rolenames[ROLE_DESKTOP_ICON] = Rolename(ROLE_DESKTOP_ICON, _('icn'), _('DesktopIcon'), _('desktop icon'))
  137. rolenames[ROLE_DESKTOP_FRAME] = Rolename(ROLE_DESKTOP_FRAME, _('frm'), _('DesktopFrame'), _('desktop frame'))
  138. rolenames[ROLE_DIAL] = Rolename(ROLE_DIAL, C_('shortbraille', 'dial'), _('Dial'), _('dial'))
  139. rolenames[ROLE_DIALOG] = Rolename(ROLE_DIALOG, _('dlg'), _('Dialog'), _('dialog'))
  140. rolenames[ROLE_DIRECTORY_PANE] = Rolename(ROLE_DIRECTORY_PANE, _('dip'), _('DirectoryPane'), _('directory pane'))
  141. rolenames[ROLE_DOCUMENT_FRAME] = Rolename(ROLE_DOCUMENT_FRAME, _('html'), _('HtmlPane'), _('html content'))
  142. rolenames[ROLE_DRAWING_AREA] = Rolename(ROLE_DRAWING_AREA, _('draw'), _('DrawingArea'), _('drawing area'))
  143. rolenames[ROLE_FILE_CHOOSER] = Rolename(ROLE_FILE_CHOOSER, _('fchsr'), _('FileChooser'), _('file chooser'))
  144. rolenames[ROLE_FILLER] = Rolename(ROLE_FILLER, _('flr'), _('Filler'), _('filler'))
  145. rolenames[ROLE_FONT_CHOOSER] = Rolename(ROLE_FONT_CHOOSER, _('fnt'), _('FontChooser'), _('font chooser'))
  146. rolenames[ROLE_FORM] = Rolename(ROLE_FORM, C_('shortbraille', 'form'), _('Form'), _('form'))
  147. rolenames[ROLE_FRAME] = Rolename(ROLE_FRAME, _('frm'), _('Frame'), _('frame'))
  148. rolenames[ROLE_GLASS_PANE] = Rolename(ROLE_GLASS_PANE, _('gpn'), _('GlassPane'), _('glass pane'))
  149. rolenames[ROLE_HEADING] = Rolename(ROLE_HEADING, _('hdng'), _('Heading'), _('heading'))
  150. rolenames[ROLE_HTML_CONTAINER] = Rolename(ROLE_HTML_CONTAINER, _('html'), _('HtmlContainer'), _('h t m l container'))
  151. rolenames[ROLE_ICON] = Rolename(ROLE_ICON, _('icn'), _('Icon'), _('icon'))
  152. rolenames[ROLE_IMAGE] = Rolename(ROLE_IMAGE, _('img'), _('Image'), _('image'))
  153. rolenames[ROLE_INTERNAL_FRAME] = Rolename(ROLE_INTERNAL_FRAME, _('ifrm'), _('InternalFrame'), _('internal frame'))
  154. rolenames[ROLE_LABEL] = Rolename(ROLE_LABEL, _('lbl'), _('Label'), _('label'))
  155. rolenames[ROLE_LAYERED_PANE] = Rolename(ROLE_LAYERED_PANE, _('lyrdpn'), _('LayeredPane'), _('layered pane'))
  156. rolenames[ROLE_LINK] = Rolename(ROLE_LINK, _('lnk'), _('Link'), _('link'))
  157. rolenames[ROLE_LIST] = Rolename(ROLE_LIST, _('lst'), _('List'), _('list'))
  158. rolenames[ROLE_LIST_ITEM] = Rolename(ROLE_LIST_ITEM, _('lstitm'), _('ListItem'), _('list item'))
  159. rolenames[ROLE_MENU] = Rolename(ROLE_MENU, _('mnu'), _('Menu'), _('menu'))
  160. rolenames[ROLE_MENU_BAR] = Rolename(ROLE_MENU_BAR, _('mnubr'), _('MenuBar'), _('menu bar'))
  161. rolenames[ROLE_MENU_ITEM] = Rolename(ROLE_MENU_ITEM, _('mnuitm'), _('MenuItem'), _('menu item'))
  162. rolenames[ROLE_OPTION_PANE] = Rolename(ROLE_OPTION_PANE, _('optnpn'), _('OptionPane'), _('option pane'))
  163. rolenames[ROLE_PAGE_TAB] = Rolename(ROLE_PAGE_TAB, _('pgt'), _('Page'), _('page'))
  164. rolenames[ROLE_PAGE_TAB_LIST] = Rolename(ROLE_PAGE_TAB_LIST, _('tblst'), _('TabList'), _('tab list'))
  165. rolenames[ROLE_PANEL] = Rolename(ROLE_PANEL, _('pnl'), _('Panel'), _('panel'))
  166. rolenames[ROLE_PASSWORD_TEXT] = Rolename(ROLE_PASSWORD_TEXT, _('pwd'), _('Password'), _('password'))
  167. rolenames[ROLE_POPUP_MENU] = Rolename(ROLE_POPUP_MENU, _('popmnu'), _('PopupMenu'), _('popup menu'))
  168. rolenames[ROLE_PROGRESS_BAR] = Rolename(ROLE_PROGRESS_BAR, _('pgbar'), _('Progress'), _('progress bar'))
  169. rolenames[ROLE_PUSH_BUTTON] = Rolename(ROLE_PUSH_BUTTON, _('btn'), _('Button'), _('button'))
  170. rolenames[ROLE_RADIO_BUTTON] = Rolename(ROLE_RADIO_BUTTON, _('radio'), _('RadioButton'), _('radio button'))
  171. rolenames[ROLE_RADIO_MENU_ITEM] = Rolename(ROLE_RADIO_MENU_ITEM, _('rdmnuitm'), _('RadioItem'), _('radio menu item'))
  172. rolenames[ROLE_ROOT_PANE] = Rolename(ROLE_ROOT_PANE, _('rtpn'), _('RootPane'), _('root pane'))
  173. rolenames[ROLE_ROW_HEADER] = Rolename(ROLE_ROW_HEADER, _('rwhdr'), _('RowHeader'), _('row header'))
  174. rolenames[ROLE_SCROLL_BAR] = Rolename(ROLE_SCROLL_BAR, _('scbr'), _('ScrollBar'), _('scroll bar'))
  175. rolenames[ROLE_SCROLL_PANE] = Rolename(ROLE_SCROLL_PANE, _('scpn'), _('ScrollPane'), _('scroll pane'))
  176. rolenames[ROLE_SECTION] = Rolename(ROLE_SECTION, _('sctn'), _('Section'), _('section'))
  177. rolenames[ROLE_SEPARATOR] = Rolename(ROLE_SEPARATOR, _('seprtr'), _('Separator'), _('separator'))
  178. rolenames[ROLE_SLIDER] = Rolename(ROLE_SLIDER, _('sldr'), _('Slider'), _('slider'))
  179. rolenames[ROLE_SPLIT_PANE] = Rolename(ROLE_SPLIT_PANE, _('spltpn'), _('SplitPane'), _('split pane'))
  180. rolenames[ROLE_SPIN_BUTTON] = Rolename(ROLE_SPIN_BUTTON, _('spin'), _('SpinButton'), _('spin button'))
  181. rolenames[ROLE_STATUSBAR] = Rolename(ROLE_STATUSBAR, _('statbr'), _('StatusBar'), _('status bar'))
  182. rolenames[ROLE_TABLE] = Rolename(ROLE_TABLE, _('tbl'), _('Table'), _('table'))
  183. rolenames[ROLE_TABLE_CELL] = Rolename(ROLE_TABLE_CELL, _('cll'), _('Cell'), _('cell'))
  184. rolenames[ROLE_TABLE_COLUMN_HEADER] = Rolename(ROLE_TABLE_COLUMN_HEADER, _('colhdr'), _('ColumnHeader'), _('column header'))
  185. rolenames[ROLE_TABLE_ROW_HEADER] = Rolename(ROLE_TABLE_ROW_HEADER, _('rwhdr'), _('RowHeader'), _('row header'))
  186. rolenames[ROLE_TEAR_OFF_MENU_ITEM] = Rolename(ROLE_TEAR_OFF_MENU_ITEM, _('tomnuitm'), _('TearOffMenuItem'), _('tear off menu item'))
  187. rolenames[ROLE_TERMINAL] = Rolename(ROLE_TERMINAL, _('term'), _('Terminal'), _('terminal'))
  188. rolenames[ROLE_TEXT] = Rolename(ROLE_TEXT, _('txt'), _('Text'), _('text'))
  189. rolenames[ROLE_ENTRY] = rolenames[ROLE_TEXT]
  190. rolenames[ROLE_TOGGLE_BUTTON] = Rolename(ROLE_TOGGLE_BUTTON, _('tglbtn'), _('ToggleButton'), _('toggle button'))
  191. rolenames[ROLE_TOOL_BAR] = Rolename(ROLE_TOOL_BAR, _('tbar'), _('ToolBar'), _('tool bar'))
  192. rolenames[ROLE_TOOL_TIP] = Rolename(ROLE_TOOL_TIP, _('tip'), _('ToolTip'), _('tool tip'))
  193. rolenames[ROLE_TREE] = Rolename(ROLE_TREE, _('tre'), _('Tree'), _('tree'))
  194. rolenames[ROLE_TREE_TABLE] = Rolename(ROLE_TREE_TABLE, _('trtbl'), _('TreeTable'), _('tree table'))
  195. rolenames[ROLE_UNKNOWN] = Rolename(ROLE_UNKNOWN, _('unk'), _('Unknown'), _('unknown'))
  196. rolenames[ROLE_VIEWPORT] = Rolename(ROLE_VIEWPORT, _('vwprt'), _('Viewport'), _('viewport'))
  197. rolenames[ROLE_WINDOW] = Rolename(ROLE_WINDOW, _('wnd'), _('Window'), _('window'))
  198. rolenames[ROLE_HEADER] = Rolename(ROLE_HEADER, _('hdr'), _('Header'), _('header'))
  199. rolenames[ROLE_FOOTER] = Rolename(ROLE_FOOTER, _('ftr'), _('Footer'), _('footer'))
  200. rolenames[ROLE_PARAGRAPH] = Rolename(ROLE_PARAGRAPH, _('para'), _('Paragraph'), _('paragraph'))
  201. rolenames[ROLE_APPLICATION] = Rolename(ROLE_APPLICATION, _('app'), _('Application'), _('application'))
  202. rolenames[ROLE_AUTOCOMPLETE] = Rolename(ROLE_AUTOCOMPLETE, _('auto'), _('AutoComplete'), _('autocomplete'))
  203. rolenames[ROLE_EDITBAR] = Rolename(ROLE_EDITBAR, _('edtbr'), _('EditBar'), _('edit bar'))
  204. rolenames[ROLE_EMBEDDED] = Rolename(ROLE_EMBEDDED, _('emb'), _('EmbeddedComponent'), _('embedded component'))
  205. _legacy_rolename_keys = rolenames.keys()
  206. for sym in dir(pyatspi):
  207.     if sym.startswith('ROLE_'):
  208.         possible_key = sym.replace('ROLE_', '').replace('_', '').lower()
  209.         for key in _legacy_rolename_keys:
  210.             if key.replace(' ', '') == possible_key:
  211.                 pyatspi_role = getattr(pyatspi, sym)
  212.                 rolenames[pyatspi_role] = rolenames[key]
  213.                 continue
  214.         
  215.  
  216.  
  217. def _adjustRole(obj, role):
  218.     '''Adjust the role to what the role really is.
  219.     '''
  220.     if role == pyatspi.ROLE_MENU_ITEM and obj.childCount > 0:
  221.         role = ROLE_MENU
  222.     
  223.     if role in [
  224.         pyatspi.ROLE_PUSH_BUTTON,
  225.         pyatspi.ROLE_MENU_ITEM]:
  226.         attributes = obj.getAttributes()
  227.         for attribute in attributes:
  228.             if attribute.startswith('haspopup:true'):
  229.                 role = ROLE_MENU
  230.                 break
  231.                 continue
  232.         
  233.     
  234.     return role
  235.  
  236.  
  237. def getSpeechForRoleName(obj, role = None):
  238.     '''Returns the localized name of the given Accessible object; the name is
  239.     suitable to be spoken.  If a localized name cannot be discovered, this
  240.     will return the string as defined by the at-spi.
  241.  
  242.     Arguments:
  243.     - obj: an Accessible object
  244.  
  245.     Returns a string containing the localized name of the object suitable
  246.     to be spoken.
  247.     '''
  248.     if not role:
  249.         pass
  250.     role = _adjustRole(obj, obj.getRole())
  251.     if not rolenames.get(role):
  252.         pass
  253.     role_entry = rolenames.get(obj.getRoleName())
  254.     if role_entry:
  255.         return role_entry.speech
  256.     debug.println(debug.LEVEL_WARNING, 'No rolename for %s' % repr(role))
  257.     localizedRoleName = obj.getLocalizedRoleName()
  258.     if localizedRoleName and len(localizedRoleName):
  259.         return localizedRoleName
  260.     return repr(role)
  261.  
  262.  
  263. def getShortBrailleForRoleName(obj, role = None):
  264.     '''Returns the localized name of the given Accessible object; the name is
  265.     a short string suitable for a Braille display.  If a localized name cannot
  266.     be discovered, this will return the string as defined by the at-spi.
  267.  
  268.     Arguments:
  269.     - obj: an Accessible object
  270.  
  271.     Returns a short string containing the localized name of the object
  272.     suitable for a Braille display.
  273.     '''
  274.     if not role:
  275.         pass
  276.     role = _adjustRole(obj, obj.getRole())
  277.     if not rolenames.get(role):
  278.         pass
  279.     role_entry = rolenames.get(obj.getRoleName())
  280.     if role_entry:
  281.         return role_entry.brailleShort
  282.     debug.println(debug.LEVEL_WARNING, 'No rolename for %s' % repr(role))
  283.     localizedRoleName = obj.getLocalizedRoleName()
  284.     if localizedRoleName and len(localizedRoleName):
  285.         return localizedRoleName
  286.     return repr(role)
  287.  
  288.  
  289. def getLongBrailleForRoleName(obj, role = None):
  290.     '''Returns the localized name of the given Accessible object; the name is
  291.     a long string suitable for a Braille display.  If a localized name cannot
  292.     be discovered, this will return the string as defined by the at-spi.
  293.  
  294.     Arguments:
  295.     - obj: an Accessible object
  296.  
  297.     Returns a string containing the localized name of the object suitable for
  298.     a Braille display.
  299.     '''
  300.     if not role:
  301.         pass
  302.     role = _adjustRole(obj, obj.getRole())
  303.     if not rolenames.get(role):
  304.         pass
  305.     role_entry = rolenames.get(obj.getRoleName())
  306.     if role_entry:
  307.         return role_entry.brailleLong
  308.     debug.println(debug.LEVEL_WARNING, 'No rolename for %s' % repr(role))
  309.     localizedRoleName = obj.getLocalizedRoleName()
  310.     if localizedRoleName and len(localizedRoleName):
  311.         return localizedRoleName
  312.     return repr(role)
  313.  
  314.  
  315. def getBrailleForRoleName(obj, role = None):
  316.     """Returns the localized name of the given Accessible object; the name is
  317.     a string suitable for a Braille display.  If a localized name cannot
  318.     be discovered, this will return the string as defined by the at-spi.
  319.  
  320.     Arguments:
  321.     - obj: an Accessible object
  322.  
  323.     Returns a string containing the localized name of the object suitable for
  324.     a Braille display.  The actual string will depend upon the value of
  325.     the 'brailleRolenameStyle' setting.
  326.     """
  327.     if settings.brailleRolenameStyle == settings.BRAILLE_ROLENAME_STYLE_SHORT:
  328.         return getShortBrailleForRoleName(obj, role)
  329.     return getLongBrailleForRoleName(obj, role)
  330.  
  331.